<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link type="text/css" rel="stylesheet" href="/webjars/bootstrap/3.3.7/css/bootstrap.css">
    <script type="text/javascript" src="/webjars/jquery/3.4.1/jquery.js"></script>
    <script type="text/javascript" src="/webjars/vue/2.6.10/dist/vue.js"></script>
    <script type="text/javascript" src="/webjars/axios/0.19.0/dist/axios.js"></script>
    <script type="text/javascript" src="/webjars/bootstrap/3.3.7/js/bootstrap.js"></script>
</head>
<body>
<div id="vuebox">
    <div class="row">
        <div class="col-md-6">
            <form class="form-inline" role="form" style="padding-left: 250px;">
                <div class="form-group" style="padding-left: 20px;">
                    <label>按区域查询:</label>
                    <select class="form-control" v-model="districtid">
                        <option value="0">不限</option>
                        <option v-for="item in districtList.data" :value="item.id">{{item.name}}</option>
                        </select>
                </div>
                <div class="form-group"  style="padding-left: 20px;">
                    <button type="button" class="btn btn-primary" @click="selectEntry(1)">查询</button>
                </div>

            </form>
        </div>
        <div class="col-md-4 text-right">
            <a @click="showQuality()" class="btn btn-primary">新增空气质量信息</a>
        </div>
    </div>
    <br>
    <table class="table table-bordered container">
        <thead>
        <tr>
            <th>编号</th>
            <th>区域名称</th>
            <th>检测时间</th>
            <th>pm10数据</th>
            <th>pm25数据</th>
            <th>监测站</th>
        </tr>
        </thead>
        <tbody>
        <tr v-for="item in qualityList.data.list">
            <td>{{item.id}}</td>
            <td><a>{{item.name}}</a></td>
            <td>{{item.monitortime}}</td>
            <td>{{item.pm10}}</td>
            <td>{{item.pm25}}</td>
            <td>{{item.monitoringstation}}</td>
        </tr>
        </tbody>
    </table>
    <br>
    <div class="text-center">
        <ul class="pagination">
            <li v-show="qualityList.data.hasPreviousPage">
                <a href="#" @click.stop="selectEntry(entryList.data.perPage)">&laquo;</a>
            </li>
            <li :class="{active:qualityList.data.pageNum==i}" v-for="i of qualityList.data.navigatepageNums">
                <a href="#" @click.stop="selectEntry(i)">{{i}}</a>
            </li>
            <li v-show="qualityList.data.hasNextPage">
                <a href="#" @click.stop="selectEntry(qualityList.data.nextPage)">&raquo;</a>
            </li>
        </ul>
    </div>


    <!--模态框-->
    <div class="modal" id="mymodal">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button class="close" type="button" >&times;</button>
                    <div class="modal-title">
                        新增空气质量信息
                    </div>
                </div>
                <div class="modal-body">
                    <form class="form-horizontal" role="form">
                        <div class="form-group">
                            <label for="districtid" class="col-sm-2 control-label">检测区域:</label>
                            <div class="col-sm-10">
                                <select id="districtId" class="form-control" v-model="new_quality.districtid">
                                    <option value="0">全部</option>
                                    <option v-for="item in districtList.data" :value="item.id">{{item.name}}</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="monitortime" class="col-sm-2 control-label">检测日期:</label>
                            <div class="col-sm-10">
                                <input v-model="new_quality.monitortime" id="monitortime" type="text" class="form-control" placeholder="请输入检测日期">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="pm10" class="col-sm-2 control-label">pm10值:</label>
                            <div class="col-sm-10">
                                <input v-model="new_quality.pm10" id="pm10" type="text" class="form-control" placeholder="请输入pm10值"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="pm25" class="col-sm-2 control-label">pm25值:</label>
                            <div class="col-sm-10">
                                <input v-model="new_quality.pm25" id="pm25" type="text" class="form-control" placeholder="请输入pm25值">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="monitoringstation" class="col-sm-2 control-label">监测站:</label>
                            <div class="col-sm-10">
                                <input v-model="new_quality.monitoringstation" id="monitoringstation" type="text" class="form-control" placeholder="请输入监测站">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="lastmodifytime" class="col-sm-2 control-label">最后检测时间:</label>
                            <div class="col-sm-10">
                                <input v-model="new_quality.lastmodifytime" id="lastmodifytime" type="text" class="form-control" placeholder="请输入最后检测时间">
                            </div>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button class="btn btn-default" @click="hideModal(),clearForm()">关闭</button>
                    <button class="btn btn-primary" @click="saveModal()">保存</button>
                </div>
            </div>
        </div>
    </div>



</div>
</body>
</html>
<script type="text/javascript">
    var vm=new Vue({
        el:"#vuebox",
        data:{
            districtList:{},
            districtid:"0",
            qualityList:{},
            saveResult:{},
            pageNum:'',
            new_quality:{districtid:'0',name:'',monitortime:'',pm10:'',pm25:'',monitoringstation:'',lastmodifytime:''}
        },
        methods:{
            selectEntry:function (pageNum) {
                axios.get("/selectQuality",{params:{districtid:this.districtid,pageNum:pageNum}}).then(res=> {
                    this.qualityList = res.data
                    this.pageNum=pageNum
                })
            },
            showQuality:function () {
                $("#mymodal").modal('show');
            },
            hideModal:function () {
                $("#mymodal").modal('hide');
            },
            clearForm:function () {
                $('#districtId').val(0);
                $('#monitortime').val('');
                $('#pm10').val('');
                $('#pm25').val('');
                $('#monitoringstation').val('');
                $('#lastmodifytime').val('');
            },
            saveModal:function () {
                axios.post("/saveQuality",this.new_quality).then(res=>{
                    this.saveResult=res.data
                    if (this.saveResult.result=='SUCCESS'){
                        this.selectEntry(this.pageNum)
                        this.hideModal();
                        this.clearForm();
                        alert("添加成功")
                    }else{
                        alert(this.saveResult.message)
                    }
                })
            }

        },
        mounted(){
            axios.get("/getDistrictList").then(res=>this.districtList=res.data)
            this.selectEntry(1);

        }
    });
</script>